package acptTests;

import java.util.Vector;

import msgParser.Strings;

import org.junit.Before;
import org.junit.Test;

import forumSystem.Forum;

import reactor.Reactor;
import tokenizer.StringMessage;

public class PolicyTest extends ServerTest{

	
	protected final int adminID = 1;
	protected int modID;
	protected int userID;
	
	protected int ForumID;
	protected int SubForumID;
	protected int TopicID;
	protected int ReplyID;
	
	protected String Policies = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" +Strings.AUTHOR_FORUM_DELETE_POST+"\0"
			  +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"+ 
	Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;
	
	protected String mail = "maximdzagoev@gmail.com";
	
	@Before
	public void setUp()
	{	
		super.setUp();
	}
	

	public String send(String str)
	{
		return sp.processMessage(new StringMessage(str) , ch).toString();
	}
	
	public void init()
	{
		send("INIT_FORUM \0 superAdmin \0 myPass");
	}
	
	public String loginSuperAdmin()
	{
		return send("ADMIN_LOGIN \0 superAdmin \0 myPass");
	}
	
	public String logout()
	{
		return send("LOGOUT");
	}
	
	public String loginUser(String user , String pass ,int forumID)
	{
		String result = send("LOG_IN \0 "+ user +" \0 "+ pass + " \0" + forumID);
		if (result.startsWith("LOGGED_IN"))
		userID = Integer.parseInt(getWord(result.toString(), 1));
		return result;
	}
	
	public String register(String user , String pass , int forumID)
	{
		String mail1 = mail+Math.random()*10000+"";
		String result = send("REGISTER \0 " + user + "\0 " + pass +" \0" + mail1 + "\0"+ forumID);
		if (result.startsWith("REGISTERED"))
		userID = Integer.parseInt(getWord(result.toString(), 1));
		return result;
	}
	
	public String addForum(String name , int AdminID)
	{
		return send("ADD_FORUM \0"+name+"\0"+AdminID+"\0"+Policies);
	}
	
	public String addForum(String name , int AdminID, String Policy)
	{
		return send("ADD_FORUM \0"+name+"\0"+AdminID+"\0"+Policy);
	}
	
	public String addSubForum(String name , int forumID , int ModID)
	{
		return send("ADD_SUBFORUM \0"+name+"\0"+forumID+"\0"+ModID);
	}
	public String addTopic(String title , String body , int subID)
	{
		return send("ADD_TOPIC \0"+title+"\0"+body+"\0"+subID);
	}
	public String addReply(String body ,  int topID)
	{
		return send("ADD_REPLY \0"+body+"\0"+topID);
	}
	public String editReply(String body ,  int repID)
	{
		return send("EDIT_REPLY \0"+body+"\0"+repID);
	}
	
	public String editPost(String body ,  int postID)
	{
		return send("EDIT_POST \0"+body+"\0"+postID);
	}
	
	public String addModerator(int userid , int subforumID)
	{
		return send("ADD_MODERATOR \0"+userid+"\0"+subforumID);
	}
	
	public String removeModerator(int userid , int subforumID)
	{
		return send("REMOVE_MODERATOR \0"+userid+"\0"+subforumID);
	}
	
	public String removeTopic(int TopicID)
	{
		return send("REMOVE_TOPIC \0"+TopicID);
	}
	
	public String addAdmin(int userid , int forumID)
	{
		return send("ADD_ADMIN \0"+userid+"\0"+forumID);
	}
	
	public void register_login(String user, String pass , int forum)
	{
		register( user ,pass , forum);
		String User = loginUser( user ,pass , forum);
		userID = Integer.parseInt(getWord(User, 1));
	}
	
	public void init_forum_logout()
	{	
		init();
		loginSuperAdmin();
		int rand = (int) (Math.random() * 10000);
		String forum = addForum("Cars"+rand , adminID);
		ForumID = Integer.parseInt(getWord(forum, 1));
		logout();
	}
	
	
	/*
	 * Tests:
	 */
	
	@Test
	public void testpostDeletion_0()
	{
		init();
		
		int whoCanDeletePost = 0;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registers evy
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//addmoderator:
		loginSuperAdmin();
		addAdmin(evyID, fid);
		logout();
		
		String user = loginUser("evy", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //admin is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		
		// Author && admin deletes: should fail:
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));		
		
	}
	@Test	
	public void testpostDeletion_1()
	{
		init();
		
		int whoCanDeletePost = 1;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, moshID); //mosh is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("evy", "1212", fid);//evy is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//moderator && admin fails:
		user = loginUser("mosh", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));
		
		//author delete succeed
		user = loginUser("evy", "1212", fid);
		fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}
	
	@Test	
	public void testpostDeletion_2()
	{
		init();
		
		int whoCanDeletePost = 2;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("mosh", "1212", fid);//mosh is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//admin && author fails:
		user = loginUser("mosh", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));
		
		//moderator delete succeed
		user = loginUser("evy", "1212", fid);
		fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}

	@Test
	public void testpostDeletion_3()
	{
		init();
		
		int whoCanDeletePost = 3;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("evy", "1212", fid);//evy is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//moderator && author fails:
		user = loginUser("mosh", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));
		
		//admin delete succeed
		user = loginUser("evy", "1212", fid);
		fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}
	
	@Test	
	public void testpostDeletion_4()
	{
		init();
		
		int whoCanDeletePost = 4;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(evyID, fid); // evy is admin
		logout();
		
		String user = loginUser("evy", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, moshID); //mosh is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("mosh", "1212", fid);//mosh is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//moderator && author fails:
		user = loginUser("mosh", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));
		
		//admin delete succeed
		user = loginUser("evy", "1212", fid);
		fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}
	
	@Test	
	public void testpostDeletion_5()
	{
		init();
		
		int whoCanDeletePost = 5;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(evyID, fid); // evy is admin
		logout();
		
		String user = loginUser("evy", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, moshID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("evy", "1212", fid);//evy is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//admin remove fail
		user = loginUser("mosh", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));
		
		//moderator & author succ
		user = loginUser("evy", "1212", fid);
		fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}
	
	@Test
	public void testpostDeletion_6()
	{
		init();
		
		int whoCanDeletePost = 6;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(evyID, fid); // evy is admin
		//logout();
		
		String user = loginUser("evyID", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("mosh", "1212", fid);//mosh is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//author remove fail
		user = loginUser("mosh", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("ERROR_REMOVE_TOPIC"));
		
		//moderator & admin succ
		user = loginUser("evy", "1212", fid);
		fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}
	
	@Test	
	public void testpostDeletion_7()
	{
		init();
		
		int whoCanDeletePost = 7;
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + whoCanDeletePost +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(evyID, fid); // evy is admin
		logout();
		
		String user = loginUser("evy", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("evy", "1212", fid);//evy is author.
		String post = addTopic("yumm", "i love sushi", subID);
		int postID = Integer.parseInt(getWord(post, 1));
		logout();
		
		//moderator & author succ
		user = loginUser("evy", "1212", fid);
		String fail = removeTopic(postID);
		logout();
		assertTrue(fail.startsWith("TOPIC_REMOVED"));
	}
	
	@Test	
	public void testaddModerator_0()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, moshID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		
		String fail = addModerator(evyID, subID);
		logout();
		if(Strings.MIN_POST_ADD_MODERATOR > 0)
		assertTrue(fail.startsWith(Strings.MODERATOR_ADDED));
		
		//MIN POSTS TIME ADD POST:
		loginUser("evy", "1212", fid);
		for (int i = 0; i < Strings.MIN_POST_ADD_MODERATOR + 1; i++) {
			addTopic("yumm"+i, "i love sushi", subID);
		}
		logout();
		
		loginUser("mosh", "1212", fid);
		fail = addModerator(evyID, subID);
		logout();
		assertTrue(fail.startsWith("MODERATOR_ADDED"));
	}
	
	
	@Test
	public void testremoveSingleModerator_0()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, moshID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		
		String fail = removeModerator(moshID, subID);
		assertTrue(fail.startsWith(Strings.ERROR_REMOVE_MODERATOR));
	}
	
	@Test
	public void testremoveSingleModerator_1()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CAN_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, moshID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		
		String fail = removeModerator(moshID, subID);
		assertTrue(fail.startsWith(Strings.MODERATOR_REMOVED));
	}
	
	
	@Test
	public void testmailValidation()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CAN_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//register user:
		String mail1 = mail+Math.random()*10000+"";
		String result = send("REGISTER \0 " + "evy" + "\0 " + "1212" +" \0" + mail1 + "\0"+ fid);
		assertTrue(result.startsWith(Strings.REGISTERED));
	}
	
	@Test
	public void testmailValidationAndCode()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CAN_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.CODE_AUTHEN_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//register user:
		String mail1 = mail+Math.random()*10000+"";
		String result = send("REGISTER \0 " + "evy" + "\0 " + "1212" +" \0" + mail1 + "\0"+ fid);
		assertTrue(result.startsWith(Strings.ACTIVATION_NEEDED));
	}
	
	
	@Test
	public void testBadWordsAllowed()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.INFORM_MODERATOR_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("evy", "1212", fid);//evy is author.
		String result = addTopic("yumm", "i fucking love sushi!", subID);
		logout();
		assertTrue(result.startsWith(Strings.TOPIC_ADDED));
	}
	
	
	
	@Test
	public void testBadWordsRejected()
	{
		init();
		
		String policy = Strings.IMMEDIATE_NOTIFY+"\0" + Strings.FORUM_MEMBERS_NOTIFY +"\0"+ 1 +"\0" + 7 +"\0"
						 +Strings.MIN_POST_ADD_MODERATOR+"\0"+Strings.CANNOT_REMOVE_SINGLE_MODERATOR+"\0"
						 +Strings.VALID_EMAIL_SECURITY+"\0" +Strings.REJECT_BAD_WORDS;

		String forumName = "Sea Food" + Math.random()*10000 + "";
		
		
		loginSuperAdmin();
		String forum1 = addForum(forumName , adminID, policy);
		int fid = Integer.parseInt(getWord(forum1, 1));
		logout();
		//forum added with the policy above..
		
		//registers mosh
		register("mosh", "1212", fid);	
		loginUser("mosh", "1212", fid);
		int moshID = userID;
		logout();
		
		// registered evy, userid = evy's id
		register("evy", "1212", fid);
		loginUser("evy", "1212", fid);
		int evyID = userID;
		logout();
		
		//add admin:
		loginSuperAdmin();
		addAdmin(moshID, fid); // mosh is admin
		logout();
		
		String user = loginUser("mosh", "1212", fid);
		String subForum1 = addSubForum("Sea Food Places", fid, evyID); //evy is moderator.
		int subID = Integer.parseInt(getWord(subForum1, 1));
		logout();
		
		loginUser("evy", "1212", fid);//evy is author.
		String result = addTopic("yumm", "i fucking love sushi!", subID);
		logout();
		assertTrue(result.startsWith(Strings.ERROR_ADD_TOPIC));
	}
}
